Splitting a string - Splitting a baseline into its components

Trying to split a string which represents a baseline
 

string baselines        = "112.1 a"
int Majperiodlocation   =       0
int Sufspacelocation    =       0
 
int offset                      = null
int periodlength
int spacelength
int stringlength                = length(baselines)
 
//find period
if(findPlainText (baselines, "2", offset, periodlength, false)){
Majperiodlocation = periodlength
}
 
if(findPlainText (baselines, " ", offset, spacelength, false)){
Sufspacelocation = spacelength
}
 
 
print baselines[0:Majperiodlocation] "\n"                                     // prints "Major"
print baselines[Majperiodlocation:Sufspacelocation]"\n"                       // prints "minor"
print baselines[Sufspacelocation:]              "\n"                          // prints "suffix"

 


the problem is, that Majperiodlocation and Sufspacelocation are both evaluating as the number 1, which is quite clearly not what i am intending to do. These integers are supposed to represent the length in the string before it finds a "." and a " " respectively.

Any ideas why these integers arn't correct?

 


liamc - Mon Mar 08 08:44:17 EST 2010

Re: Splitting a string - Splitting a baseline into its components
liamc - Mon Mar 08 08:59:14 EST 2010

apologies, silly error...
 

string baselines        = "112.1 a"
int Majperiodlocation   =       0
int Sufspacelocation    =       0
 
int offsetperiod                        = null
int offsetspace                         = null
int periodlength                        = null
int spacelength                 = null
int slength                             = length(baselines)
 
//find period
if(findPlainText (baselines, ".", offsetperiod, periodlength, false)){
Majperiodlocation = offsetperiod
}
 
if(findPlainText (baselines, " ", offsetspace, spacelength, false)){
Sufspacelocation = offsetspace
}
 
//print offsetperiod
//print offsetspace
print baselines[0:(offsetperiod-1)]                     "\n"                          // prints "Major"
print baselines[(offsetperiod):offsetspace]     "\n"                          // prints "minor"
print baselines[offsetspace:]                   "\n"                          // prints "suffix"

Re: Splitting a string - Splitting a baseline into its components
SystemAdmin - Mon Mar 08 10:56:19 EST 2010

liamc - Mon Mar 08 08:59:14 EST 2010

apologies, silly error...
 

string baselines        = "112.1 a"
int Majperiodlocation   =       0
int Sufspacelocation    =       0
 
int offsetperiod                        = null
int offsetspace                         = null
int periodlength                        = null
int spacelength                 = null
int slength                             = length(baselines)
 
//find period
if(findPlainText (baselines, ".", offsetperiod, periodlength, false)){
Majperiodlocation = offsetperiod
}
 
if(findPlainText (baselines, " ", offsetspace, spacelength, false)){
Sufspacelocation = offsetspace
}
 
//print offsetperiod
//print offsetspace
print baselines[0:(offsetperiod-1)]                     "\n"                          // prints "Major"
print baselines[(offsetperiod):offsetspace]     "\n"                          // prints "minor"
print baselines[offsetspace:]                   "\n"                          // prints "suffix"

Not sure I understand the question... When I run your code I get "112\n.1\n a", so all you need to do is add a "+1" to your first offsets when printing the minor number and suffix of the baseline to get the correct substring.

Why are you parsing baseline strings? I ask because there may be easier ways to do whatever conversion you need done.

Re: Splitting a string - Splitting a baseline into its components
jsarkic - Mon Mar 08 11:38:17 EST 2010

liamc - Mon Mar 08 08:59:14 EST 2010

apologies, silly error...
 

string baselines        = "112.1 a"
int Majperiodlocation   =       0
int Sufspacelocation    =       0
 
int offsetperiod                        = null
int offsetspace                         = null
int periodlength                        = null
int spacelength                 = null
int slength                             = length(baselines)
 
//find period
if(findPlainText (baselines, ".", offsetperiod, periodlength, false)){
Majperiodlocation = offsetperiod
}
 
if(findPlainText (baselines, " ", offsetspace, spacelength, false)){
Sufspacelocation = offsetspace
}
 
//print offsetperiod
//print offsetspace
print baselines[0:(offsetperiod-1)]                     "\n"                          // prints "Major"
print baselines[(offsetperiod):offsetspace]     "\n"                          // prints "minor"
print baselines[offsetspace:]                   "\n"                          // prints "suffix"

Once you get a baseline handle, you can use the following perms to get info on the baseline. No need to parse.

int major(Baseline b)
int minor(Baseline b)
string suffix(Baseline b)
string annotation(Baseline b)
string user(Baseline b)
Date dateOf(Baseline b)